package com.lyl.momanapp.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.lyl.momanapp.R;
import com.lyl.momanapp.bean.Facials;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/1/23.
 */


public class HorizontalListViewAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private int selectIndex = -1;

    List<Facials> allFacials = new ArrayList<>();

    public HorizontalListViewAdapter(Context context, List<Facials> allFacials) {
        this.mContext = context;
        this.allFacials = allFacials;
        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);//LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return allFacials.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.horizontal_list_item, null);
            holder.mImage = (ImageView) convertView.findViewById(R.id.item_face_zhaoxiao);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (position == selectIndex) {
            convertView.setSelected(true);
        } else {
            convertView.setSelected(false);
        }


        ImageLoader.getInstance().displayImage(allFacials.get(position).getThumbnail(), holder.mImage);

        return convertView;
    }

    private static class ViewHolder {
        private ImageView mImage;
    }


    public void setSelectIndex(int i) {
        selectIndex = i;
    }
}